import 'package:flutter/material.dart';
import 'package:demo/EMPABEmployeeModel.dart';  // 确保你有一个对应的员工模型文件

/// EMPABDepartmentModel类 - 代表部门信息
class EMPABDepartmentModel {
  final String id;              // 部门的唯一标识符
  final String name;            // 部门简称
  final String fullName;        // 部门全称
  final int sortNo;             // 部门排序
  final int timestamp;          // 时间戳
  final String parentId;        // 父部门id
  final String status;          // 部门状态
  final String orgHasJunior;    // 是否有下级部门
  // final bool company;           // 是否是公司
  final String namePinyin;      // 名称的拼音，用于模糊查询
  final int membersCount;       // 成员个数
  // final List<EMPABEmployeeModel> members; // 部门成员列表
  final int onlineMembersCount; // 在线成员个数
  final bool isSelect;          // 是否具有选择框
  final int selectStatus;       // 选中状态
  final int shortCutStatus;     // 快捷方式状态

  EMPABDepartmentModel({
    required this.id,
    required this.name,
    required this.fullName,
    required this.sortNo,
    required this.timestamp,
    required this.parentId,
    required this.status,
    required this.orgHasJunior,
    // required this.company,
    required this.namePinyin,
    required this.membersCount,
    // required this.members,
    required this.onlineMembersCount,
    required this.isSelect,
    required this.selectStatus,
    required this.shortCutStatus,
  });

  // 从JSON数据创建对象的工厂构造函数
  factory EMPABDepartmentModel.fromJson(Map<String, dynamic> json) {
    return EMPABDepartmentModel(
      id: json['id'],
      name: json['name'],
      fullName: json['fullName'],
      sortNo: json['sortNo'],
      timestamp: json['timestamp'],
      parentId: json['parentId'],
      status: json['status'],
      orgHasJunior: json['orgHasJunior'],
      // company: json['company'] == 1,
      namePinyin: json['namePinyin'],
      membersCount: json['membersCount'],
      // members: List<EMPABEmployeeModel>.from(json['members'].map((x) => EMPABEmployeeModel.fromJson(x))),
      onlineMembersCount: json['onlineMembersCount'],
      isSelect: json['isSelect'],
      selectStatus: json['selectStatus'],
      shortCutStatus: json['shortCutStatus'],
    );
  }

  // 将对象转换为JSON格式的方法
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
      'fullName': fullName,
      'sortNo': sortNo,
      'timestamp': timestamp,
      'parentId': parentId,
      'status': status,
      'orgHasJunior': orgHasJunior,
      // 'company': company ? 1 : 0,
      'namePinyin': namePinyin,
      'membersCount': membersCount,
      // 'members': members.map((x) => x.toJson()).toList(),
      'onlineMembersCount': onlineMembersCount,
      'isSelect': isSelect,
      'selectStatus': selectStatus,
      'shortCutStatus': shortCutStatus,
    };
  }
}
